package com.jcnet.bizaia;

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.MenuItem;
import com.jcnet.bizaia.bean.DiscussSearchInfoBean;
import com.jcnet.bizaia.bean.VodSearchInfoBean;
import com.jcnet.bizaia.bean.VoiceSearchBean;
import com.jcnet.bizaia.fragment.DiscussionSearchForResultFragment;
import com.jcnet.bizaia.fragment.VodSearchForResultFragment;
import com.jcnet.bizaia.fragment.VoiceDetailFragmentForSearch;
import com.jcnet.bizaia.inter_face.SetCategory;
import com.loopj.android.http.RequestParams;

import android.os.Bundle;
import android.support.v4.app.Fragment;

public class SearchResultActivity extends SherlockFragmentActivity  {

	private DiscussSearchInfoBean discussSearchInfoBean;
	
	private VodSearchInfoBean vodSearchInfoBean;
	
	private VoiceSearchBean voiceSearchBean;
	
	private Fragment fragment;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.simple_fragment_lay);
		
		initActionBars();
		//
		/**
		 * @param
		 *  参数名称	参数类型	说明
			languageNum	int	语言种类：1：中文2：英文3：日文
			title	string	讲座标题
			disidNum	int	地区id
			iidNum	int	行业id检索 （默认全部时赋值-1）
			holddateNum	date	时间日期检索（搜索全部时赋值null/-1等均可）
			crmoneyNum	int	费用检索 （搜索全部时赋值-1）
			useridNum	int	用户id(用户未登录赋值-1)
			pageNum	int	当前第几页（默认第一页）
			pageSizeNum	int	当前分页显示条数（默认20条）
		 */
		discussSearchInfoBean = (DiscussSearchInfoBean) getIntent().getSerializableExtra("searchItem");
		
		vodSearchInfoBean = (VodSearchInfoBean)getIntent().getSerializableExtra("vodSearchItem");
		
		voiceSearchBean = (VoiceSearchBean)getIntent().getSerializableExtra("voiceSearchItem");
		
		
		if(discussSearchInfoBean!=null){
			RequestParams params = new RequestParams();
			params.put("languageNum", App.localeCode+"");
			params.put("title", discussSearchInfoBean.getSerarchTitltString());     	//搜索时候标题
			params.put("disidNum", discussSearchInfoBean.getSearchAdressID()+"");   //地区ID
			params.put("iidNum", discussSearchInfoBean.getSearchCategoryID()+"");   	//行业ID
			params.put("holddateNum", discussSearchInfoBean.getSearchDate()+"");  //时间检索 
			params.put("crmoneyNum", -1+"");   //费用 检索
			params.put("useridNum", -1+"");     //用户id 默认-1
			System.out.println("params"+params+"________________________");
			fragment =new DiscussionSearchForResultFragment(params);
		}
		
		
		if(vodSearchInfoBean!=null){
			
			RequestParams params = new RequestParams();
			params.put("languageNum", App.localeCode+"");
			params.put("title", vodSearchInfoBean.getVodSearchTitle());     	//搜索时候标题
			params.put("cidNum", vodSearchInfoBean.getVodSearchCategoryID()+"");   //分类id检索
			params.put("iidNum", vodSearchInfoBean.getVodSearchBusinessCategoryID()+"");   	//行业ID
			params.put("useridNum", -1+"");     //用户id 默认-1
			
			fragment = new VodSearchForResultFragment(params);
			
		}
		
		if(voiceSearchBean!=null){
			RequestParams params = new RequestParams();
			params.put("languageNum", App.localeCode+"");
			params.put("datelineNum", voiceSearchBean.getVoiceSearchDate());     	//音频时间 
			params.put("title", voiceSearchBean.getVoiceSearchTitle()+"");     	//音频标题
			params.put("cidNum", voiceSearchBean.getVoiceCategoryID()+"");     	//音频ID
			
			fragment = VoiceDetailFragmentForSearch.newInstance(params);
		}
		getSupportFragmentManager().beginTransaction().replace(R.id.fragment, fragment).commit();
		
	}
	private void initActionBars() {
		// TODO Auto-generated method stub
		ActionBar actionBar = getSupportActionBar();
		actionBar.setDisplayHomeAsUpEnabled(true);
		actionBar.setDisplayUseLogoEnabled(false);
		actionBar.setDisplayShowTitleEnabled(true);  //是否显示标题 m
		actionBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.top_bg));
		setTitle(getString(R.string.search));
		actionBar.setSubtitle(getString(R.string.disucessSearch));
		actionBar.show();
	}
	
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		switch (item.getItemId()) {
		case android.R.id.home:
			finish();
			break;

		default:
			break;
		}
		
		return super.onOptionsItemSelected(item);
	}
}
